package domain;

import physical.CardReader;
import physical.CashDispenser;
import physical.ReceiptPrinter;

public class ATM {
    public ATM() {
        this.cardReader = new CardReader();
        this.cashDipenser = new CashDispenser();
        this.receiptPrinter = new ReceiptPrinter();
        this.curAccount = new Account();

    }

    private CardReader cardReader;
    private CashDispenser cashDipenser;
    private ReceiptPrinter receiptPrinter;

	private Transaction curTransaction;
    private Account curAccount;
    private String curMessageType;

    public static final String DEVICE_NUMBER = "XX000001";
    public static final String MAX_AMOUNT_PER_WITHDRAWAL = "2500";


	public Account makeNewIdentification(String cardNumber){
		curAccount = cardReader.readCard(cardNumber);
		return curAccount;
	}

	public boolean enterPassword(String password) {
		return cardReader.verifyPassword(password);
	}


	public void makeNewTransaction(String transType){
		switch (transType){
			case "\u53d6\u6b3e": curTransaction = new Withdrawal(curAccount);break;
			case "\u5b58\u6b3e": curTransaction = new Deposit(curAccount);
		}
	}

	public void enterAmount(String amount) {
		curTransaction.updateAmount(amount);
	}

	public String takeCash(){
	    return cashDipenser.cashOut(curTransaction.getAmount());
    }

    public String putCash(){
	    return cashDipenser.cashIn(curTransaction.getAmount());
    }

	public void endTransaction(){
		curTransaction.endTransaction();
	}


	public  String isToPrintReceipt(boolean x) {
		return x ? (receiptPrinter.printReceipt(curTransaction)) : ("");
	}

	public void refundCard(){
		this.curAccount = cardReader.refundCard();
	}

    public CardReader getCardReader() {
        return cardReader;
    }

    public void setCardReader(CardReader cardReader) {
        this.cardReader = cardReader;
    }

    public CashDispenser getCashDipenser() {
        return cashDipenser;
    }

    public void setCashDipenser(CashDispenser cashDipenser) {
        this.cashDipenser = cashDipenser;
    }

    public ReceiptPrinter getReceiptPrinter() {
        return receiptPrinter;
    }

    public void setReceiptPrinter(ReceiptPrinter receiptPrinter) {
        this.receiptPrinter = receiptPrinter;
    }

    public Transaction getCurTransaction() {
        return curTransaction;
    }

    public void setCurTransaction(Transaction curTransaction) {
        this.curTransaction = curTransaction;
    }

    public Account getCurAccount() {
        return curAccount;
    }

    public void setCurAccount(Account curAccount) {
        this.curAccount = curAccount;
    }

    public String getCurMessageType() {
        return curMessageType;
    }

    public void setCurMessageType(String curMessageType) {
        this.curMessageType = curMessageType;
    }
}
